﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dillon.CSV
{

    class Token
    {
        internal readonly int kind;
        internal readonly int col;
        internal readonly int line;
        internal readonly string originalValue;
        internal readonly string val;
        internal readonly int columnIndex;
        internal readonly int rowIndex;

        internal Token next;
        readonly Location endLocation;

        public int Kind
        {
            get { return kind; }
        }



        public object LiteralValue
        {
            get { return originalValue; }
        }

        public string Value
        {
            get { return val; }
        }

        public Location EndLocation
        {
            get { return endLocation; }
        }

        public Location Location
        {
            get
            {
                return new Location(col, line);
            }
        }

        public Location CSVLocation
        {
            get
            {
                return new Location(columnIndex, rowIndex);
            }
        }

        public Token(int kind, int col, int line, int columnIndex, int rowIndex)
            : this(kind, col, line, columnIndex, rowIndex, "", "")
        {
        }

        public Token(int kind, int col, int line, int columnIndex, int rowIndex, string value)
            : this(kind, col, line, columnIndex, rowIndex, value, value)
        {

        }

        public Token(int kind, int col, int line, int columnIndex, int rowIndex, string realStringValue, string originalStringValue)
        {
            this.kind = kind;
            this.col = col;
            this.line = line;
            this.val = realStringValue;
            this.columnIndex = columnIndex;
            this.rowIndex = rowIndex;
            this.endLocation = new Location(col + (string.IsNullOrEmpty(originalStringValue) ? 1 : originalStringValue.Length), line);
            this.originalValue = originalStringValue;
        }


    }
}
